// 个股因子暴露度
// zhanghaitao
import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { SecondHeaderC, TableC } from '../../../../../../comps';
import SetColumns from '../../../comps/selectColumnsC';
@connect(({ loading, exposureAnalysisM }) => ({ loading, exposureAnalysisM }))
export default class IndividualExposure extends PureComponent {
  static defaultProps = {
    onRef: () => {}, // 本组件的引用
  };
  constructor(props) {
    super(props);
    this.state = {
      newColumns: [], // 表格列头
      dataSource: [], // 表格数据
      currentPage: 1, // 当前页码
      numInPage: 10, // 每页条数
    };
  }
  componentDidMount() {
    this.getTableDate(this.props.searchData);
  }

  UNSAFE_componentWillReceiveProps(nextProps) {
    if (JSON.stringify(nextProps.searchData) !== JSON.stringify(this.props.searchData)) {
      this.getTableDate(nextProps.searchData);
    }
  }

  // 获取表格数据
  getTableDate = (searchData) => {
    let querys = { ...searchData };
    delete querys.needPenetrate;
    delete querys.portfolioName;
    delete querys.timeRange;
    this.props.dispatch({
      type: 'exposureAnalysisM/getTableDate',
      payload: querys,
      callback: (dataSource) => {
        this.onChange();
        if (dataSource) {
          this.setState({ dataSource });
        } else {
          this.setState({ dataSource: [] });
        }
      },
    });
  };

  // 表格页码排序改变调用
  handleTableChange = (pagination) => {
    const { current, pageSize } = pagination;
    if (this.state.isReset) {
      //判断是否点击了重置 点击页码不进行后台查询
      message.warning('查询条件已被重置，请重新查询。');
      this.setState({
        isReset: false,
      });
      return;
    }
    this.setState({
      currentPage: current,
      numInPage: pageSize,
    });
  };

  // 表格列优化
  onChange = () => {
    const {
      exposureAnalysisM: { columns },
    } = this.props;
    let newColumns = columns.filter((i) => i.display);
    this.setState({ newColumns });
  };

  // 列选择
  selectOnChange = (newColumnsInfo, checkedKeysInfo) => {
    this.props.dispatch({
      type: 'exposureAnalysisM/save',
      payload: {
        columns: newColumnsInfo,
        checkedKeysInfo: checkedKeysInfo,
      },
    });
  };

  render() {
    const {
      exposureAnalysisM: { columns, checkedKeysInfo },
    } = this.props;
    const { newColumns, dataSource, currentPage, numInPage } = this.state;
    return (
      <div>
        <SecondHeaderC title='个股风格因子暴露度' />
        页面暂未开放，敬请期待！
        {/* <SecondHeaderC title='个股风格因子暴露度'
                    Right={<SetColumns
                        checkedKeysInfo={checkedKeysInfo}
                        columns={columns}
                        onChange={this.onChange}
                        selectOnChange={this.selectOnChange}
                    />} />
                <TableC
                    columns={newColumns}
                    loading={this.props.loading.effects['exposureAnalysisM/getTableDate']}
                    dataSource={dataSource}
                    current={currentPage}
                    pageSize={numInPage}
                    scroll={{ x: 'max-content' }}
                    rowKey='id'
                    onChange={this.handleTableChange}
                /> */}
      </div>
    );
  }
}
